$(function(){

	//全反选
	$("#checkall").click(function(){
		$("input[name='id[]']").each(function(){
			if(this.checked == false){
				this.checked = true;
			}
			else{
				this.checked = false;
			}			
		});
	});


    //分页按钮
    var $btnPagerJump    = $('#btnPagerJump');
    var $pager_jump_page = $('#pager_jump_page');

    if($btnPagerJump.length){

        $btnPagerJump.click(function(){

            var page    = $pager_jump_page.val();
            page = parseInt(page);

            if(isNaN(page) || page <=0){
                page = 1;
            }

            var max     = $pager_jump_page.attr('max');

            if(page > max){
                alert('最大页数为' + max);
                return false;
            }

            var link = $pager_jump_page.attr('link');
            window.location = link.replace(/\$page/g,page);

        });

        $pager_jump_page.keydown(function(event){
            switch(event.keyCode) {
                case 13:
                    $btnPagerJump.click();
                    break;
            }
        });
    }


});

//添加到购物车
function addCart(goods_id,goods_number,goods_attr){
	$.post('/index.php/Cart/add',{
		'goods_id':goods_id,
		'goods_number':goods_number,
		'goods_attr':goods_attr
		},function(data){
		if(data.success){
			location.href = '/index.php/Cart/';
		}else{
			alert('商品放入购物车 失败');
		}
	},'json');
}

//检验是否是email
function isEmail(mail){
  return (new RegExp(/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}$/i).test(mail));
}

//检验是否是手机号
function isMobilePhone(phone){
  return (new RegExp(/^1{1}([3|5|8]){1}\d{9}$/).test(phone));
}


//是否为ie6
function isIE(){
	var version = navigator.userAgent;
	var re = new RegExp('MSIE');
	return re.test(version);
}

//是否为ie6
function isIE6(){
	var version = navigator.userAgent;
	var re = new RegExp('MSIE 6\.0');
	return re.test(version);
} 

//切换
function SwapTab(name,cls_show,cls_hide,cnt,cur){
    for(var i=1;i<=cnt;i++){
		if(i==cur){
			 $('#div_'+name+'_'+i).show();
			 $('#tab_'+name+'_'+i).attr('class',cls_show);
		}else{
			 $('#div_'+name+'_'+i).hide();
			 $('#tab_'+name+'_'+i).attr('class',cls_hide);
		}
	}
}

//获取后缀的id="name-id"
function GetPostfix(id){
	return id.substring(id.lastIndexOf('-',id) + 1);
}